<?php
class classFollow extends phpajax{
	function input(){
            aread('follow_value');
	}
	
        /**
         * 
         * if input <b>follow_value is numeric and bigger than 0</b> 
         * the result will be product detail with price<br />
         * 
         * if input <b>follow_value is numeric and smaller than 0</b>
         * the result will be product detail without price<br /><br />
         * 
         * 
         * if input <b>follow_value is not numeric (it is string)</b> 
         * the result will be only input string
         */
	function main(){
            $follow_value = & $this->follow_value;
            if($follow_value!='' and is_numeric($follow_value))
                aprint('follow_container',self::geProductPreview($follow_value));
            else
                aprint('follow_container',$follow_value);
	}
	
	public function getJS($follow_value){
            return '
                onmouseover="
                    document.getElementById(\'follow_value\').value = \''.$follow_value.'\';
                    classFollow();
                    document.getElementById(\'follow_container\').style.width = \'100px\';
                    document.getElementById(\'follow_container\').style.height = \'auto\';
                    document.getElementById(\'follow_container\').style.visibility = \'visible\';
                    document.onmousemove = follow;
                "
                onmouseout="
                    document.getElementById(\'follow_container\').innerHTML=\'\';
                    document.getElementById(\'follow_container\').style.visibility = \'hidden\';				
                    document.onmousemove = null;
                "
            ';
	}

	public function getClosingJS(){
            return '
                    document.getElementById(\'follow_container\').innerHTML=\'\';
                    document.getElementById(\'follow_container\').style.visibility = \'hidden\';
                    document.onmousemove = null;
            ';
	}

        /**
         * 
         * if value of <b>iProductID is bigger than 0</b> the result is with price<br />
         * if value of <b>iProductID is smaller than 0</b> the result is without price
         */
	private function geProductPreview($iProductID){
            $result = '';
            if($iProductID>0) $iRealProductID=$iProductID; else $iRealProductID=-1*$iProductID;
            //make image's form
            $product_image = self::getImage($iRealProductID);
            //make others data	
            $sql_result = mysql_query('select Product_Name,Product_Price,Product_Descr FROM products WHERE ID='.$iRealProductID);	
            $sql_object = mysql_fetch_object($sql_result);
            $_Price = new classPriceExport();

            //fast test, if product was selected in db (if is saved in DB)
            if($sql_object->Product_Name!='' and $sql_object->Product_Price!=''){
                $product_short_name = $sql_object->Product_Name;
                if($iProductID>0) $product_short_price 	= $_Price->simplePrice($iProductID,1);//$sql_object->Product_Price._CURRENCY1_;
                $product_short_desc = substr($sql_object->Product_Descr,0,_TEXTS_LENGHT_IN_PREVIEW_);

                //product form from template
                $_Skin = new classTemplate();
                include $_Skin->getActual().'/product_short.inc.php';
            }
            else return _i18n_product_DETAIL_INFORMATIONS_ABOUT_PRODUCT_ARENT_AVAILABLE_;

            return $result;
	}
        
	private function getImage($imgID){
            if(
                file_exists(_PRODUCTS_IMAGE_DIR_.'/'.$imgID._IMAGES_FILE_TYPE_) and
                file_exists(_PRODUCTS_IMAGE_DIR_.'/'.$imgID._PREVIEW_IMAGE_SUFFIX_._IMAGES_FILE_TYPE_)
            )
                $result ='
                    <img 
                        class="css_product_detail_preview_image"
                        src="'._PRODUCTS_IMAGE_DIR_.'/'.$imgID._PREVIEW_IMAGE_SUFFIX_._IMAGES_FILE_TYPE_.'"
                    >
                ';
            else
                $result ='';	
            return $result;
	}
}
?>